<template>
    <div>
        <el-dialog title="货重修改" :visible.sync="dialogForm" width="800px">
            <el-form :inline="true" ref="form" class="add-form" label-width="150px">
                <el-form-item label="车皮号:">
                    {{carnum.wagonNo}}
                </el-form-item>
            </el-form>
            <el-table :data="sendLists" style="width: 100%" border>
                <el-table-column type="index" fixed="left" label="序号" width="50"></el-table-column>
                <el-table-column prop="containerNo" label="箱号" width="120"></el-table-column>
                <el-table-column prop="containerSize" label="尺寸"></el-table-column>
                <el-table-column prop="containerType" label="箱型"></el-table-column>
                <el-table-column prop="ifHeavy" label="空重" >
                    <template slot-scope="scope">
                        <div v-if="sendLists!==null&&sendLists.length===2">
                            <div style="padding-bottom:8px">
                                {{sendLists[scope.$index].ifHeavy | _filterIfHeavyType}}
                            </div>
                        </div>
                        <div v-else-if="sendLists!==null&&sendLists.length===1">
                            {{ sendLists[0].ifHeavy | _filterIfHeavyType}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="" label="货重（吨）">
                    <template slot-scope="scope">
                        <el-input v-model="scope.row.input" placeholder="请输入内容" clearable></el-input>
                    </template>
                </el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogForm = false">取 消</el-button>
                <el-button type="primary" @click="handleSubmit" :loading="$store.getters.loadingBtn">保 存</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {
        Tocargo
    } from "@/api/gatePanel/gatePanel";

    export default {
        name: "Tocargo",
        data() {
            return {
                dialogForm: false,
                carnum: {},
                sendLists: [],
                input: ''
            }
        },
        mounted() {
        },
        methods: {
            // 保存
            handleSubmit() {
                for (let i = 0; i < this.sendLists.length; i++) {
                    if (this.sendLists[i].ifHeavy === 'F') {
                        if (this.sendLists[i].input > 5 && this.sendLists[i].input < 45) {
                            console.log('成功')
                        } else {
                            this.$message({ showClose: true, message: '空重状态与重量不相符', type: 'warning' });
                            return;
                        }
                    } else {
                        if (this.sendLists[i].input > 1 && this.sendLists[i].input < 5) {
                            console.log('成功')
                        } else {
                            this.$message({ message: '空重状态与重量不相符', type: "warning" });
                            return;
                        }
                    }
                }
                let data = {
                    planNo: '',
                    containers: [],
                    wagonNo: ''
                }
                this.sendLists.forEach(el => {
                    let a = {
                        id: el.id,
                        containerNo: el.containerNo,
                        cargoWeight: el.input
                    }
                    data.containers.push(a)
                })
                data.wagonNo = this.carnum.wagonNo
                data.planNo = this.carnum.planNo
                Tocargo(data).then(res => {
                    console.log(this.sendLists)
                    this.$message({ message: "修改货重成功", type: "success" });
                    this.dialogForm = false;
                    this.$emit('aaa');
                })

            }
        }
    }
</script>

<style scoped>

</style>
